package com.zhangln.mountbuzhou.controller;


import com.zhangln.mountbuzhou.dto.BaseResponse;
import com.zhangln.mountbuzhou.dto.request.PushMsgReq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author sherry
 * @since 2020-04-27
 */
@RestController
@RequestMapping("/test")
@Slf4j
public class TestTableController {

    @Autowired
    private RabbitTemplate rabbitTemplate;


    @GetMapping("/test1")
    public void test2() {
    }

    @PostMapping(value = "/pushmsg", params = {"channelId", "msg"})
    public BaseResponse pushMsg(String channelId, String msg) {
        log.info("往  {}  推送消息  {}", channelId, msg);
        PushMsgReq req = new PushMsgReq();
        req.setPushId(UUID.randomUUID().toString());
        req.setArea("330206");
        req.setBody(msg);
        rabbitTemplate.convertAndSend("WEB_SOCKET_PUSH_MSG_QUEUE", req);
        return new BaseResponse("推送成");
    }

}

